Stored Procedures [dbo].[asi_ScheduleWorkflow]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@itemCountint4
SQL Script
/****** Object:  Stored Procedure dbo.asi_ScheduleWorkflow    Script Date: 7/3/2003 4:58:05 PM ******/
CREATE PROCEDURE asi_ScheduleWorkflow

@itemCount int = 3

AS

--======================================================================
--Update the appropriate number of rows with a UniqueIdentifier to mark them as 'Selected'
--======================================================================

--Get a new GUID
DECLARE @id uniqueidentifier
SET @id=newid()

DECLARE @tmp nvarchar(600)

SET @tmp = 'UPDATE WorkflowQueue SET SelectionKey = ''' + CAST(@id AS nvarchar(40)) + ''' '
SET @tmp = @tmp + 'FROM WorkflowQueue wfq '
SET @tmp = @tmp + 'WHERE wfq.WorkFlowQueueKey IN (SELECT TOP ' + CAST(@itemCount as nvarchar(10)) + ' WorkFlowQueueKey '
SET @tmp = @tmp + 'FROM WorkflowQueue '
SET @tmp = @tmp + 'WHERE SelectionKey IS NULL '
SET @tmp = @tmp + 'ORDER BY CreatedOn ASC) '
SET @tmp = @tmp + 'AND wfq.SelectionKey IS NULL'

--Update the values of up to the top three rows
EXEC (@tmp)

--======================================================================
--Select the rows previously marked for execution and return them to the client
--======================================================================

SELECT WorkFlowQueueKey FROM WorkflowQueue WHERE SelectionKey = @id

GO
Uses